Skip to content

Conversation

@anoadragon453
Copy link
Member

@anoadragon453 anoadragon453 commented Oct 20, 2025

This PR converts the "Name/topic keys are correct" sytest to Complement.

This was spawned from said test failing in element-hq/synapse#19071, and not wanting to debug perl.

The test was first converted to go via Claude Code, then verified manually. Finally, the test failed when modifying what Synapse returns for /publicRooms, which is what we want to see.

@anoadragon453 anoadragon453 requested review from a team as code owners October 20, 2025 17:27
anoadragon453 added a commit to matrix-org/sytest that referenced this pull request Oct 20, 2025
This test has been migrated to Complement, see
matrix-org/complement#811
As 15s would be quite long to wait until the test failed.
This allows us to collect all incorrect data about a room and print it.
A side-effect is that one doesn't need to re-run the tests to see all
the broken fields.

In addition, the `must.MatchGJSON` was changed to a `should`, which now
re-polls `/publicRooms`. This prevents the test from exiting early upon
receiving an entry that's missing some keys.
A more accurate name for it.
This is indeed much easier to follow, and less book-keeping.
Otherwise we were (correctly) seeing the warning about unexpected rooms
in every time other than the first.
This will be a no-op if the room was already private.
return false
if len(validationErrors) > 0 {
for _, e := range validationErrors {
t.Errorf("Validation error for room %s: %s", roomID, e.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use errors.Join(...) instead of looping 🤔?

(I don't know)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I wasn't aware of this method - that's cool to learn about. There's an example in the documentation of how to use it.

I think how it'd work is something like the following:

var validationErrors error

err := doSomething()
if err !=nil {
	errors.Join(validationErrors, err)
}

...a few more of those...

if validationErrors != nil {
	t.Fatalf("Validation errors for room %s:\n %s", roomID, validationErrors)
}

which would avoid the loop. Though I don't think it's as readable than the simple array of errors. There's also probably a loop involved in displaying validationErrors anyways?

I think I'll leave it how it is for now, but TIL about said method, and combining errors in go in general.

Copy link
Collaborator

@MadLittleMods MadLittleMods Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another shout: The new meta for creating an error from another is to use %w ("error wrapping), ex. fmt.Errorf("failed to generate signing key: %w", err)

See https://go.dev/doc/go1.13#error_wrapping

Calling it out because I also learned about it recently when going over a codebase with golangci-lint

@anoadragon453 anoadragon453 merged commit 7e5c85b into main Nov 10, 2025
7 of 8 checks passed
@anoadragon453 anoadragon453 deleted the anoa/sytest_name_topic_keys_are_correct branch November 10, 2025 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants